#!/bin/bash
#   ConVirt   -  Copyright (c) 2008 Convirture Corp.
#   ======
#
# ConVirt is a Virtualization management tool with a graphical user
# interface that allows for performing the standard set of VM operations
# (start, stop, pause, kill, shutdown, reboot, snapshot, etc...). It
# also attempts to simplify various aspects of VM lifecycle management.
#
#
# This software is subject to the GNU General Public License, Version 2 (GPLv2)
# and for details, please consult it at:
#
#    http://www.gnu.org/licenses/old-licenses/gpl-2.0.txt
# 
#
# author : mkelkar@users.sourceforge.net
#

# contains utility function useful during the storage detail operations
#



function check_prerequisite {
 if [ "" != "$1" ]; then
   is_dameon_installed=`ps -ef | grep "${1}" | grep -v grep`
   if [ "$is_dameon_installed" == "" ]; then
     echo "ERROR:The ${1} dameon is not running"
     exit 1
   fi
 fi
 is_cmd_installed=`which ${2} 2>/dev/null`
 if [ $? != 0 ]; then
   echo "ERROR:The ${2} is not installed"
   exit 1
 fi
}

function check_function_return_value {
  if [ $? !=  0 ]; then
    echo "ERROR:$1"
    exit 1
  fi
}

function parse_field_values {
  
  
  if [ "$1" != "" ] && [ "$2" != "" ]; then
    #for nameValue in `echo $1 | xargs -d'|'`
    
    for nameValue in `echo $1 | tr '|' ' '`
    do
      # echo "$nameValue"
      if echo "$nameValue" | grep $2 >/dev/null
      then
        value=`echo $nameValue | cut -d'=' -f2`
      fi
    done
  fi
}

function isRequiedParamPresent {
  if [ "${1}" == "" ]; then
    echo "ERROR:The required parameter ${2} is missing."
    exit 1
  fi
}


